﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Tayninh2011
{
    public sealed partial class FrmRule : Form
    {
        #region Fields

        private DataSet xaDs = new DataSet();
        ITnExToolsDataManager toolData = new TnExToolsDataManager();

        #endregion Fields

        #region Singleton

        private static readonly FrmRule meForm = new FrmRule();
        private FrmRule()
        {
            InitializeComponent();
        }
        public static FrmRule CallMe
        {
            get { return meForm; }
        }

        public new void Show()
        {
            if (isShown)
            {
                base.Show();
            }
            else
            {
                base.Show();
                isShown = true;
            }
        }
        private static bool isShown = false;
        static FrmRule()
        {

            meForm.FormClosing += new FormClosingEventHandler(meForm_FormClosing);

        }
        private static void meForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            isShown = false;
            meForm.Hide();
        }

        #endregion Singleton

        private void FrmRule_Load(object sender, EventArgs e)
        {
            bwkXa.RunWorkerAsync();
        }

        private void bwkXa_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                string dieukien = "select * from " + TnFeatureClassName.XA;
                xaDs = toolData.TnQueryBySQL(RootForm.UserInfo, dieukien);
            }
            catch
            {
                
            }
        }

        private void bwkXa_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                dgvXa.DataSource = xaDs.Tables[0];
            }
            catch { }
        }
    }
}
